#include <iostream>
using namespace std;

struct node
{
    struct node *lchild= nullptr;
    struct node *rchild= nullptr;
    char data;
};

char c;
int i;

void build(node* &T)
{
    if(i==0)
    {
        i=1;
    }
    else
    {
        cin>>c;
    }
    if(c=='#')
    {
        T = nullptr;
    }
    else
    {
        T=new node;
        T->data=c;
        build(T->lchild);
        build(T->rchild);
    }
}

void print(node * T)
{
    if(nullptr!=T)
    {
        print(T->lchild);
        cout<<T->data<<" ";
        print(T->rchild);
    }
}


int main() {
    while(scanf("%c",&c)!=EOF)
    {
        i=0;
        node *T;
        build(T);
        print(T);
        cout<<endl;
        scanf("%*c");
    }
    return 0;
}
